const axios = require('axios');
const lz = require("../utils/lzString");
const aes = require("../utils/aesUtil");

const service = axios.create({
    timeout: 10 * 1000,
    headers: {"Content-Type": 'application/x-www-form-urlencoded'}
})

service.interceptors.request.use(
    (config) => {
        config.data = aes.encrypt(lz.compressToBase64(config.data));
        return config;
    },
    (error) => {
        console.log('Request Err');
        return error;
    }
);

service.interceptors.response.use(
    (response) => {
        response.data.MsgData = JSON.parse(lz.decompressFromBase64(aes.decrypt(response.data.MsgData)));
        return response;
    },
    (error) => {
        return Promise.reject(error);
    }
);

module.exports = {
    service
}